﻿// 判断今年是否是闰年
int Thisyear = DateTime.Now.Year;
bool isleapyear = Thisyear % 4 == 0 || Thisyear % 400 == 0;
//如果是闰年则Isleapyear等于0，否则为1
int Isleapyear = Convert.ToInt32(isleapyear);
//取一个今年每月的日数的数组
int[] days = { 31, 28 + Isleapyear, 31, 30, 31, 30, 31, 31, 30, 31, 30,31 };
//设立当年第一天的日期
string thefirstday = "2022-01-01";
DateTime Thefirstday = Convert.ToDateTime(thefirstday);
DateTime Theday = Thefirstday;
//光标初始位置
int x = 0, y = 0;
//一共有四行
for (int i = 0; i < 4; i++)
{
    ///对每一行进行处理

    //输入每行每月前两行文字
    for (int j = 0; j < 3; j++)
    {
        x = 14 + 30 * j; y = 10 * i;
        Console.SetCursorPosition(x, y);
        //输出每月数字
        int a = j + 1 + 3 * i;
        Console.Write(a);
        Console.Write("月");
        x = 30 * j; y = 10 * i + 1;
        Console.SetCursorPosition(x, y);
        Console.Write(new String("日 一 二 三 四 五 六"));
    }
    //一行当中的三个月
    for (int j = 0; j < 3; j++)
    { //将光标的位置移动到相应的位置
        x = 30 * j; y = 10 * i + 2;
        Console.SetCursorPosition(x, y);
        //输入每月第一天前面的空格
        int n = (int)Theday.DayOfWeek;
        Console.Write(new String(' ', 3 * n ));
        //每个月30/1天
        for (int k = 0; k < days[j + 3 * i]; k++)
        {
            //输入日期
            if(k+1<10) Console.Write(" ");
            Console.Write( k + 1);
            Console.Write(" ");
            //当前是星期几
            n = (int)Theday.DayOfWeek;
            //如果当前是星期六，光标移到下一行第一列;
            if (n == 6)
                Console.SetCursorPosition(x, ++y);
            //接下来将输入的日期
            Theday = Theday.AddDays(1);

        }
    }






}








